package curves.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.EtchedBorder;
import curves.Surface;
import curves.math.ChaikinCurveAlgorithm;
import curves.sys.IntersectionEngine;
import curves.sys.SimpleCurve;
import curves.sys.SplinesSurface;

public class Window extends JFrame {

    private GraphicEngine engine;
    private final JLabel statusbar;

    public Window() {
        super("Curves and Splines");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        MainRighClickMenu menu = new MainRighClickMenu(this);
        PointMenu pointMenu = new PointMenu(this);

        IntersectionEngine interEngine = new IntersectionEngine();
        Surface surface = new SplinesSurface(interEngine);
        engine = new GraphicEngine(this, surface, menu, pointMenu);


        surface.addCurve(new SimpleCurve(surface, new ChaikinCurveAlgorithm()));
        surface.setCurrentCurve(surface.getCurves().get(0));
        getContentPane().add(engine);
        
        statusbar = new JLabel(" ");
        statusbar.setBorder(BorderFactory.createEtchedBorder(
                EtchedBorder.RAISED));
        getContentPane().add(statusbar, BorderLayout.SOUTH);

        menu.setSurface(surface);
        pointMenu.setSurface(surface);

        pack();

        Toolkit tk = Toolkit.getDefaultToolkit();
        Dimension screenSize = tk.getScreenSize();
        int screenHeight = screenSize.height;
        int screenWidth = screenSize.width;
        setSize(screenWidth / 2, screenHeight / 2);
        setLocation(screenWidth / 4, screenHeight / 4);

        setVisible(true);
    }

    public GraphicEngine getGraphicEngine() {
        return engine;
    }

    public JLabel getStatusBar(){
        return statusbar;
    }
}
